package cn.net.bhb.base.utils;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by zkt on 2018-8-14.
 * Description: 单例
 */

public class SingletonUtil {
    private static final ConcurrentHashMap<Class, Object> map = new ConcurrentHashMap<>();

    private static <T> T getSingleton(Class<T> type) {
        Object ob = map.get(type);
        if (ob == null) {
            try {
                synchronized (map) {
                    ob = type.newInstance();
                    map.put(type, ob);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return (T) ob;
    }

    public static <T> void remove(Class<T> type) {
        map.remove(type);
    }
}
